home *** CD-ROM | disk | FTP | other *** search
- /*------------------------------------------------------------------------------
- # MPing 1.1 - MacTCP Ping Tool
- #
- # Copyright © Apple Computer, Inc. 1990-1991
- # All rights reserved.
- #
- # Versions:
- # 1.1 September 25, 1991.
- #
- # File:
- # MPing.c
- #
- # Components:
- # AddressXlation.h
- # MacTCPCommonTypes.h
- # Makefile
- # MiscIPPB.h
- # MPing.c
- # MPing.h
- # MPing.r
- # MPingDlg.c
- # MPingExtern.h
- # MPingGlobals.h
- # MPingIcmp.c
- # MPingWindow.c
- # resolver.c
- ------------------------------------------------------------------------------*/
-
- #include <values.h>
- #include <types.h>
- #include <quickdraw.h>
- #include <fonts.h>
- #include <events.h>
- #include <controls.h>
- #include <windows.h>
- #include <menus.h>
- #include <textedit.h>
- #include <dialogs.h>
- #include <desk.h>
- #include <scrap.h>
- #include <toolutils.h>
- #include <memory.h>
- #include <segload.h>
- #include <files.h>
- #include <osutils.h>
- #include <osevents.h>
- #include <diskinit.h>
- #include <packages.h>
- #include <traps.h>
- #include <strings.h>
- #include <Errors.h>
- #include <Devices.h>
- #include <String.h>
- #include <StdLib.h>
- #include <StdIO.h>
-
- #include "MacTCPCommonTypes.h"
- #include "MPing.h" /* bring in all the #defines for MPing */
- #include "MPingGlobals.h" /* bring in some structure definitions for MPing */
- #include "MPingExtern.h" /* all extern variables */
-
- extern void Terminate(void);
- extern void DrawOnScreen(void);
- void DoInitDialog(DialogPtr ldialog);
- void DoDialogItem(DialogPtr ldialog, short itemHit);
-
- void DoPingGo(DialogPtr ldialog, Handle itHandle);
- void DoPingStop(DialogPtr ldialog, Handle itHandle);
- void DoQuit(void);
- void DoHostAddrEdit(Handle itHandle);
- void DoSendTextRadio(DialogPtr ldialog, Handle itHandle);
- void DoSendTextEdit(Handle itHandle);
- void DoSendPatternRadio(DialogPtr ldialog, Handle itHandle);
- void DoSendPatternEdit(Handle itHandle);
- void DoPacketSizeEdit(Handle itHandle);
- void DoQuietRadio(DialogPtr ldialog, Handle itHandle);
- void DoVerboseRadio(DialogPtr ldialog, Handle itHandle);
- void DoNoOfPktsCheck(DialogPtr ldialog, Handle itHandle);
- void DoNoOfPktsEdit(Handle itHandle);
- void DoWaitSecEdit(Handle itHandle);
- void DoSendASyncCheck(Handle itHandle);
- extern OSErr IcmpPingSetup(void);
- extern void DrawErrorMessageOnScreen(short errMsg);
-
- Str255 zHostAddr, zData, zPattern, zSize, zCount, zWait;
-
-
- void DoDialogItem(ldialog, itemHit)
- DialogPtr ldialog;
- short itemHit;
- {
- short titType;
- Handle titHandle;
- Rect titDispRect;
- short uFlag=1;
-
- GetDItem(ldialog, itemHit, &titType, &titHandle, &titDispRect);
- switch (itemHit) {
- case PINGGO_BUTTON:
- if (!gRunning)
- DoPingGo(ldialog, titHandle);
- break;
- case PINGSTOP_BUTTON:
- if (gRunning)
- DoPingStop(ldialog, titHandle);
- break;
- case QUIT_BUTTON:
- DoQuit();
- if (!gRunning)
- break;
- case HOSTADDR_EDIT:
- if (!gRunning)
- DoHostAddrEdit(titHandle);
- break;
- case SENDTEXT_RADIO:
- if (!gRunning)
- DoSendTextRadio(ldialog, titHandle);
- break;
- case SENDTEXT_EDIT:
- if (!gRunning)
- DoSendTextEdit(titHandle);
- break;
- case SENDPATTERN_RADIO:
- if (!gRunning)
- DoSendPatternRadio(ldialog, titHandle);
- break;
- case SENDPATTERN_EDIT:
- if (!gRunning)
- DoSendPatternEdit(titHandle);
- break;
- case PACKETSIZE_EDIT:
- if (!gRunning)
- DoPacketSizeEdit(titHandle);
- break;
- case QUIET_RADIO:
- if (!gRunning)
- DoQuietRadio(ldialog, titHandle);
- break;
- case VERBOSE_RADIO:
- if (!gRunning)
- DoVerboseRadio(ldialog, titHandle);
- break;
- case NOOFPKTS_CHECK:
- if (!gRunning)
- DoNoOfPktsCheck(ldialog, titHandle);
- break;
- case NOOFPKTS_EDIT:
- if (!gRunning)
- DoNoOfPktsEdit(titHandle);
- break;
- case WAITSEC_EDIT:
- if (!gRunning)
- DoWaitSecEdit(titHandle);
- break;
- default:
- break;
- }
- }
-
- void DoHostAddrEdit(itHandle)
- Handle itHandle;
- {
- GetIText(itHandle,zHostAddr);
- SetIText(itHandle,zHostAddr);
- strcpy((char *) gHostAddress, (char *) p2cstr(zHostAddr));
- }
-
- void DoSendTextRadio(ldialog, itHandle)
- DialogPtr ldialog;
- Handle itHandle;
- {
- short titType;
- Handle titHandle;
- Rect titDispRect;
-
- SetCtlValue((ControlHandle) itHandle, 1);
- ShowDItem(ldialog, SENDTEXT_EDIT);
- GetDItem(ldialog, SENDPATTERN_RADIO, &titType, &titHandle, &titDispRect);
- SetCtlValue((ControlHandle) titHandle, 0);
- HideDItem(ldialog, SENDPATTERN_EDIT);
- gTextPattern = true;
- }
-
- void DoSendTextEdit(itHandle)
- Handle itHandle;
- {
- GetIText(itHandle,zData);
- SetIText(itHandle,zData);
- strcpy(gData, p2cstr(zData));
- }
-
- void DoSendPatternRadio(ldialog, itHandle)
- DialogPtr ldialog;
- Handle itHandle;
- {
- short titType;
- Handle titHandle;
- Rect titDispRect;
-
- SetCtlValue((ControlHandle) itHandle, 1);
- ShowDItem(ldialog, SENDPATTERN_EDIT);
- GetDItem(ldialog, SENDTEXT_RADIO, &titType, &titHandle, &titDispRect);
- SetCtlValue((ControlHandle) titHandle, 0);
- HideDItem(ldialog, SENDTEXT_EDIT);
- gTextPattern = false;
- }
-
- void DoSendPatternEdit(itHandle)
- Handle itHandle;
- {
- GetIText(itHandle,zPattern);
- SetIText(itHandle,zPattern);
- strcpy(gPattern, p2cstr(zPattern));
- }
-
- void DoPacketSizeEdit(itHandle)
- Handle itHandle;
- {
- GetIText(itHandle,zSize);
- SetIText(itHandle,zSize);
- gSize = atoi(p2cstr(zSize));
- }
-
- void DoQuietRadio(ldialog, itHandle)
- DialogPtr ldialog;
- Handle itHandle;
- {
- short titType;
- Handle titHandle;
- Rect titDispRect;
-
- SetCtlValue((ControlHandle) itHandle, 1);
- GetDItem(ldialog, VERBOSE_RADIO, &titType, &titHandle, &titDispRect);
- SetCtlValue((ControlHandle) titHandle, 0);
- gQuietVerbose = true;
- }
-
- void DoVerboseRadio(ldialog, itHandle)
- DialogPtr ldialog;
- Handle itHandle;
- {
- short titType;
- Handle titHandle;
- Rect titDispRect;
-
- SetCtlValue((ControlHandle) itHandle, 1);
- GetDItem(ldialog, QUIET_RADIO, &titType, &titHandle, &titDispRect);
- SetCtlValue((ControlHandle) titHandle, 0);
- gQuietVerbose = false;
- }
-
- void DoNoOfPktsCheck(ldialog, itHandle)
- DialogPtr ldialog;
- Handle itHandle;
- {
- short uFlag=1;
-
- uFlag = GetCtlValue((ControlHandle) itHandle);
- if (uFlag == 1) {
- uFlag = 0;
- SetCtlValue((ControlHandle) itHandle, uFlag);
- HideDItem(ldialog, NOOFPKTS_EDIT);
- gFixedNoOfPkts = false;
- }
- else {
- uFlag = 1;
- SetCtlValue((ControlHandle) itHandle, uFlag);
- ShowDItem(ldialog, NOOFPKTS_EDIT);
- gFixedNoOfPkts = true;
- }
- }
-
- void DoNoOfPktsEdit(itHandle)
- Handle itHandle;
- {
- GetIText(itHandle,zCount);
- SetIText(itHandle,zCount);
- gCount = atoi(p2cstr(zCount));
- }
-
- void DoWaitSecEdit(itHandle)
- Handle itHandle;
- {
- GetIText(itHandle,zWait);
- SetIText(itHandle,zWait);
- gWait = atoi(p2cstr(zWait));
- }
-
- void DoPingGo(ldialog, itHandle)
- DialogPtr ldialog;
- Handle itHandle;
- {
- short titType;
- Handle titHandle;
- Rect titDispRect;
-
- if (IcmpPingSetup() == noErr) {
- gRunning = true;
- gSessionComplete = false;
- HideControl((ControlHandle) itHandle);
- GetDItem(ldialog, PINGSTOP_BUTTON, &titType, &titHandle, &titDispRect);
- ShowControl((ControlHandle) titHandle);
- DrawHostInfoOnScreen();
- }
- else {
- SysBeep(10);
- DrawHostInfoOnScreen();
- DrawErrorMessageOnScreen(sHostNotResp);
- }
- }
-
- void DoPingStop(ldialog, itHandle)
- DialogPtr ldialog;
- Handle itHandle;
- {
- short titType;
- Handle titHandle;
- Rect titDispRect;
-
- gRunning = false;
- gSessionComplete = true;
- HideControl((ControlHandle) itHandle);
- GetDItem(ldialog, PINGGO_BUTTON, &titType, &titHandle, &titDispRect);
- ShowControl((ControlHandle) titHandle);
-
- gIcmpStat.pktLoss = (gIcmpStat.totPktOut == 0 ? 0 :
- ((100.0 * (double)(gIcmpStat.totPktOut - gIcmpStat.totPktIn))/(double)gIcmpStat.totPktOut));
- gIcmpStat.avgTime = (gIcmpStat.totPktIn == 0 ? 0 : gIcmpStat.totTime/(unsigned long) gIcmpStat.totPktIn);
-
- DrawOnScreen();
- }
-
- void DoQuit(void)
- {
- Terminate();
- }
-
- void DoInitDialog(ldialog)
- DialogPtr ldialog;
- {
- short titType;
- Handle titHandle;
- Rect titDispRect;
-
- gHostAddress[0] = '\0';
- gData[0] = '\0';
- gPattern[0] = '\0';
- gSize=DEFAULT_ICMP_SIZE;
- gCount=DEFAULT_PKT_COUNT;
- gWait=ICMP_TIME_DELAY;
- gTextPattern=true;
- gQuietVerbose=true;
- gFixedNoOfPkts=true;
-
- strcpy((char *) zHostAddr, gHostAddress);
- c2pstr(zHostAddr);
- strcpy((char *) zData, gData);
- c2pstr(zData);
- strcpy((char *) zPattern, gPattern);
- c2pstr(zPattern);
- NumToString((long) gSize, zSize);
- NumToString((long) gCount, zCount);
- NumToString((long) gWait, zWait);
-
- GetDItem(ldialog, HOSTADDR_EDIT, &titType, &titHandle, &titDispRect);
- SetIText(titHandle, zHostAddr);
-
- if (gTextPattern == true) {
- GetDItem(ldialog, SENDTEXT_RADIO, &titType, &titHandle, &titDispRect);
- SetCtlValue((ControlHandle) titHandle, 1);
- GetDItem(ldialog, SENDTEXT_EDIT, &titType, &titHandle, &titDispRect);
- SetIText(titHandle, zData);
-
- GetDItem(ldialog, SENDPATTERN_RADIO, &titType, &titHandle, &titDispRect);
- SetCtlValue((ControlHandle) titHandle, 0);
- HideDItem(ldialog, SENDPATTERN_EDIT);
- }
- else {
- GetDItem(ldialog, SENDTEXT_RADIO, &titType, &titHandle, &titDispRect);
- SetCtlValue((ControlHandle) titHandle, 0);
- HideDItem(ldialog, SENDTEXT_EDIT);
-
- GetDItem(ldialog, SENDPATTERN_RADIO, &titType, &titHandle, &titDispRect);
- SetCtlValue((ControlHandle) titHandle, 1);
- GetDItem(ldialog, SENDPATTERN_EDIT, &titType, &titHandle, &titDispRect);
- SetIText(titHandle, zPattern);
- }
-
- GetDItem(ldialog, PACKETSIZE_EDIT, &titType, &titHandle, &titDispRect);
- SetIText(titHandle, zSize);
-
- if (gQuietVerbose == true) {
- GetDItem(ldialog, QUIET_RADIO, &titType, &titHandle, &titDispRect);
- SetCtlValue((ControlHandle) titHandle, 1);
- GetDItem(ldialog, VERBOSE_RADIO, &titType, &titHandle, &titDispRect);
- SetCtlValue((ControlHandle) titHandle, 0);
- }
- else {
- GetDItem(ldialog, QUIET_RADIO, &titType, &titHandle, &titDispRect);
- SetCtlValue((ControlHandle) titHandle, 0);
- GetDItem(ldialog, VERBOSE_RADIO, &titType, &titHandle, &titDispRect);
- SetCtlValue((ControlHandle) titHandle, 1);
- }
-
- if (gFixedNoOfPkts == true) {
- GetDItem(ldialog, NOOFPKTS_CHECK, &titType, &titHandle, &titDispRect);
- SetCtlValue((ControlHandle) titHandle, 1);
- GetDItem(ldialog, NOOFPKTS_EDIT, &titType, &titHandle, &titDispRect);
- SetIText(titHandle, zCount);
- }
- else {
- GetDItem(ldialog, NOOFPKTS_CHECK, &titType, &titHandle, &titDispRect);
- SetCtlValue((ControlHandle) titHandle, 0);
- HideDItem(ldialog, NOOFPKTS_EDIT);
- }
-
- GetDItem(ldialog, WAITSEC_EDIT, &titType, &titHandle, &titDispRect);
- SetIText(titHandle, zWait);
-
- if (gRunning == false) {
- GetDItem(ldialog, PINGSTOP_BUTTON, &titType, &titHandle, &titDispRect);
- HideControl((ControlHandle) titHandle);
- GetDItem(ldialog, PINGGO_BUTTON, &titType, &titHandle, &titDispRect);
- ShowControl((ControlHandle) titHandle);
- }
- else {
- GetDItem(ldialog, PINGGO_BUTTON, &titType, &titHandle, &titDispRect);
- HideControl((ControlHandle) titHandle);
- GetDItem(ldialog, PINGSTOP_BUTTON, &titType, &titHandle, &titDispRect);
- ShowControl((ControlHandle) titHandle);
- }
- }
-